// ./swagger/index.js
var path = require("path");
var express = require("express");
var swaggerUi = require("swagger-ui-express");
var swaggerJSDoc = require("swagger-jsdoc");

const options = {
  definition: {
    // 采用的 openapi 版本
    openapi: "3.0.0",
    // 页面基本信息
    info: {
      title: "猫眼管理系统API接口说明", // 设置 swagger 的标题。（项目名称）
      version: "1.0.0" //设置版本
    },
    components: {
      securitySchemes: {
        oauth2: {
          type: "oauth2",
          flows: {
            authorizationCode: {
              authorizationUrl: "/oauth/dialog",
              tokenUrl: "/oauth/token"
            }
          }
        }
      },
      schemas: {
        // 用户名
        users: {
          properties: {
            _id: {
              type: "string"
            },
            username: {
              type: "string"
            },
            password: {
              type: "string"
            }
          }
        },
        // 管理员
        admins: {
          properties: {
            _id: {
              type: "string"
            },
            username: {
              type: "string"
            },
            password: {
              type: "string"
            }
          }
        },
        // 正在热映
        movies: {
          properties: {
            _id: {
              type: "string",
              description: "唯一标识"
            },
            cname: {
              type: "string",
              description: "电影名"
            },
            ename: {
              type: "string",
              description: "电影英文名"
            },
            type: {
              type: "string",

              description: "电影的类型"
            },
            area: {
              type: "string",
              description: "电影首映地区"
            },
            posterImg: {
              type: "array",
              items: {
                type: "string"
              }
            },
            time: {
              type: "number",
              description: "电影时长"
            },
            upDate: {
              type: "string",
              description: "电影大陆上映时间·"
            },
            score: {
              type: "number",
              description: "电影评分"
            },
            count: {
              type: "string",
              description: "电影票房"
            },
            intro: {
              type: "string",
              description: "剧情介绍"
            },
            isClassic: {
              type: "boolean",
              description: "是否是经典"
            },
            director: {
              type: "string",
              description: "导演名字"
            },
            actor: {
              type: "string",
              description: "演员名字"
            },
            headImg: {
              type: "array",
              items: {
                type: "string"
              }
            },
            setImg: {
              type: "array",
              items: {
                type: "string"
              }
            }
          }
        },
        // 即将上映
        releaseMovies: {
          properties: {
            _id: {
              type: "string",
              description: "唯一标识"
            },
            cname: {
              type: "string",
              description: "电影名"
            },
            ename: {
              type: "string",
              description: "电影英文名"
            },
            type: {
              type: "string",

              description: "电影的类型"
            },
            area: {
              type: "string",
              description: "电影首映地区"
            },
            time: {
              type: "number",
              description: "电影时长"
            },
            upDate: {
              type: "string",
              description: "电影大陆上映时间·"
            },
            sees: {
              type: "number",
              description: "想看数"
            },
            count: {
              type: "string",
              description: "电影票房"
            },
            intro: {
              type: "string",
              description: "剧情介绍"
            },
            isClassic: {
              type: "boolean",
              description: "是否是经典"
            },

            director: {
              type: "string",
              description: "导演名字"
            },
            actor: {
              type: "string",
              description: "演员名字"
            },
            images: {
              type: "array",
              items: {
                type: "string"
              }
            }
          }
        },
        // 影院
        admins: {
          properties: {
            _id: {
              type: "string",
              description: "唯一标识"
            },
            name: {
              type: "string",
              description: "影院名称"
            },
            phone: {
              type: "string",
              description: "影院联系方式"
            },
            address: {
              type: "string",
              description: "影院地址"
            },
            status: {
              type: " Boolean",
              description: "是否营业"
            },
            imgs: {
              type: "array",
              items: {
                type: "string"
              }
            }
          }
        },
        // 排片
        schedules: {
          properties: {
            movieId: {
              type: "string",
              description: "电影的唯一标识"
            }, // 电影 id    
            cinemasId: {
              type: "string",
              description: "影院的唯一标识"
            }, // 影院 id    
            theaterId: {
              type: "string",
              description: "放映厅的唯一标识"
            }, // 放映厅 id    
            day: {
              type: "string",
              description: "日期"
            }, // 放映时间 id    
            time: {
              type: "string",
              description: "时间"
            },
            price: {
              type: "string",
              description: "价格"
            },
          }
        },
        // 排片集合的关联数据
        schedules: {
          properties: {
            movieId: {
              type: "Object",
              items: {
                $ref: "#/components/schemas/movies"
              }
            }, // 电影 id    
            cinemasId: {
              type: "string",
              description: "影院的唯一标识"
            }, // 影院 id    
            theaterId: {
              type: "string",
              description: "放映厅的唯一标识"
            }, // 放映厅 id    
            day: {
              type: "string",
              description: "日期"
            }, // 放映时间 id    
            time: {
              type: "string",
              description: "时间"
            },
            price: {
              type: "string",
              description: "价格"
            },
          }
        },
        schedulesId: {
          properties: {
            _id: {
              type: "string",
              description: "排片信息_id"
            },
            movieId: {
              type: "object",
              description: "电影信息"
            }, // 电影 id    
            cinemasId: {
              type: "object",
              description: "影院信息"
            }, // 影院 id    
            theaterId: {
              type: "object",
              description: "放映厅信息"
            }, // 放映厅 id    
            day: {
              type: "string",
              description: "日期"
            }, // 放映时间 id    
            time: {
              type: "string",
              description: "时间"
            },
            price: {
              type: "string",
              description: "价格"
            },
          }
        },
        //删除排片
        deleteschediles:{
          properties:{
            _id: {
              type: "string",
              description: "唯一标识"
            },
            movies_id: {
              type: "string",
              description: "电影ID"
            },
          }
        },
        // updataSched修改排片
        updataSched:{
          properties:{
            _id: {
              type: "string",
              description: "唯一标识"
            },
            movies_id:{
              type: "string",
              description: "电影id"
            },
            theaterId:{
              type: "string",
              description: "影厅id"
            },
            price:{
              type: "string",
              description: "价格"
            },
            showTime:{
              type: "string",
              description: "时间"
            },
            date:{
              type: "string",
              description: "日期"
            },
          }
        },
        // 放映厅
        theaters: {
          properties: {
            _id: {
              type: "string",
              description: "唯一标识"
            },
            name: {
              type: "string",
              description: "放映厅名称"
            },
            cinemasId: {
              type: "string",
              description: "放映厅所属影院"
            },
            status: {
              type: " Boolean",
              description: "是否营业"
            }
          }
        },
        // 座位
        seats: {
          properties: {
            _id: {
              type: "string",
              description: "唯一标识"
            },
            row: {
              type: "Number",
              description: "座位行号"
            },
            col: {
              type: "Number",
              description: "座位列号"
            },
            theaterId: {
              type: " Boolean",
              description: "座位所从属的放映厅"
            }
          }
        },
        // 选座
        seating: {
          properties: {
            _id: {
              type: "string",
              description: "唯一标识"
            },
            scheduleId: {
              type: "String",
              description: "排片 id"
            },
            seatId: {
              type: "String",
              description: "座位 id"
            }
          }
        },
            // 订单
             indent: {
              properties: {
                _id: {
                  type: "string",
                  description: "唯一标识"
                },
                usersNameId: {
                  type: "string",
                  description: "用户id"
                },
                movieId: {
                  type: "string",
                  description: "电影id"
                },
                cinemasId: {
                  type: "string",
                  description: "影院id"
                },
                theaterId: {
                  type: "string",
                  description: "放映厅id"
                },
                scheduleId: {
                  type: "String",
                  description: "排片 id"
                },
                seatId: {
                  type: "String",
                  description: "座位 id"
                },
                  seatingId: {
              type: "string",
              description: "选座id"
            },
              }
            },
        // 影院分页
        ArrayOfcinemas: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/cinemas"
              }
            }
          }
        },
        // 电影分页
        ArrayOfmovies: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/movies"
              }
            }
          }
        },
        // 电影分页
        ArrayOfreleaseMovies: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/releaseMovies"
              }
            }
          }
        },
        // 排片分页
        ArrayOfschedules: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/schedules"
              }
            }
          }
        },
        // 排片分页
        ArrayOfschedulesId: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/schedulesId"
              }
            }
          }
        },
        // 放映厅分页
        ArrayOftheaters: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/theaters"
              }
            }
          }
        },
        // 座位分页
        ArrayOfseats: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/seats"
              }
            }
          }
        },
        // 选座分页
        ArrayOfseating: {
          properties: {
            total: {
              type: "number"
            },
            maxPage: {
              type: "number"
            },
            rows: {
              type: "array",
              items: {
                $ref: "#/components/schemas/seating"
              }
            }
          }
        },
           // 订单分页
           ArrayOfindent: {
            properties: {
              total: {
                type: "number"
              },
              maxPage: {
                type: "number"
              },
              rows: {
                type: "array",
                items: {
                  $ref: "#/components/schemas/indent"
                }
              }
            }
          },
      }
    }
  },
  // 去指定项目路径下收集 swagger 注释，用于生成swagger文档。
  apis: [path.join(__dirname, "../routes/**/*.js")]
};
var swaggerJson = function (req, res) {
  res.setHeader("Content-Type", "application/json");
  res.send(swaggerSpec);
};
const swaggerSpec = swaggerJSDoc(options);

var swaggerInstall = function (app) {
  if (!app) {
    app = express();
  }
  // 根据配置自动生成 swagger.json 文件
  app.get("/swagger.json", swaggerJson);
  // 使用 swaggerSpec 生成 swagger 文档页面，并开放在指定路由
  app.use("/swagger", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
};
module.exports = swaggerInstall;